﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
using System.Threading.Tasks;
using Volo.Abp;

namespace mozhi.smarterp.Finance.Files
{
    [RemoteService]
    [Route("api/v1/files")]
    public class FileController : BaseController
    {
        private IFileAppService _appService;

        public FileController(IFileAppService appService)
        {
            _appService = appService;
        }


        [HttpPost]
        public async Task<FileDto> CreateAsync([FromForm] IFormFile file)
        {
            var result = await _appService.UploadFileAsync(file);

            return result;
        }


        [HttpGet]
        [Route("download")]
        public async Task<IActionResult> DownloadFileAsync(Guid id)
        {
            var result = await _appService.DownloadFileAsync(id);

            return File(result.Item1, result.Item2, result.Item3);
        }
    }
}
